//
//  HYFStatusToolBar.m
//  MyOCWeibo
//
//  Created by 黄勇锋 on 16/10/9.
//  Copyright © 2016年 黄勇锋. All rights reserved.
//

#import "HYFStatusToolBar.h"

@interface HYFStatusToolBar()

@property (strong, nonatomic) NSMutableArray *spliteLines;

@property (strong, nonatomic) NSMutableArray *buttons;

@end


@implementation HYFStatusToolBar

- (NSMutableArray *)spliteLines{
    
    if (!_spliteLines) {
        
        _spliteLines = [NSMutableArray array];
    }
    return _spliteLines;
}

- (NSMutableArray *)buttons{
    
    if (!_buttons) {
        _buttons = [NSMutableArray array];
    }
    return _buttons;
}



- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self addChildButtonWithImageName:@"timeline_icon_retweet" title:@"转发"];
        [self addChildButtonWithImageName:@"timeline_icon_comment" title:@"评论"];
        [self addChildButtonWithImageName:@"timeline_icon_unlike" title:@"赞"];
        
        //添加2条分割线
        [self addSpliteLine];
        [self addSpliteLine];
        
    }
    return self;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    //计算 button
    NSInteger count = self.buttons.count;
    CGFloat childWidth = self.width / self.buttons.count;
    
    for (int i = 0; i< count; i++) {
        
        UIView *child = self.buttons[i];
        //设置大小
        child.width = childWidth;
        child.height = self.height;
        //设置x值
        child.x = childWidth * i;
    }
    
    //计算分割线
    for (int i = 0; i < self.spliteLines.count ; i++) {
        
        UIView *child = self.spliteLines[i];

        child.x = (i + 1) * childWidth - child.width * 0.5;
    }
}

- (void)addSpliteLine{
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"timeline_card_bottom_line"]];
    
    [self addSubview:imageView];
    
    [self.spliteLines addObject:imageView];
    
}

- (void)addChildButtonWithImageName:(NSString *)imgName title:(NSString *)title{
    
    UIButton *button = [[UIButton alloc]init];
    
    //设置背景图片
    [button setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_background_highlighted"]  forState:UIControlStateHighlighted];
    
    [button setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    
    button.titleLabel.font = SYS_FONT(15);
    
    [self addSubview:button];
    
    [self.buttons addObject:button];
}






@end
